/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package station3d.states;

import station3d.*;
import station3d.graphics.*;
import station3d.math.*;

import java.awt.event.*;
import com.sun.opengl.util.texture.*;

/**
 *
 * @author Martin
 */
public class Simulation extends GameState {

    
    private CameraController cameraController;

    private Terrain terrain;

    


    private InputManager.InputState escapePressed = new InputManager.InputState(InputManager.InputState.InputStateBehavior.CATCH_ONLY_ONCE);




    @Override
    public void init() throws ResourceError {
        cameraController = new CameraController(inputManager);

        inputManager.setKeyboardStateObject(KeyEvent.VK_ESCAPE, escapePressed);

        terrain = resourceManager.loadTerrain("media/blender/terrainTest.obj",
                100,
                resourceManager.loadTexture("media/blender/terrainTest.texture.png"),
                resourceManager.loadTexture("media/blender/terrainTest.texture.detail.png"),
                50);
        
    }

    @Override
    public void shutdown() {
        
        terrain.dispose();

    }

    @Override
    public void update(long deltaTime) {

        

        // aktualizovat kameru
        cameraController.updateCamera(deltaTime);
    }

    @Override
    public void draw(Renderer r) {

        r.setCameraPosition(cameraController.getCameraPosition());
        r.setCameraXRotation(cameraController.getCameraXRotation());
        r.setCameraYRotation(cameraController.getCameraYRotation());
        r.setup3D();

        r.enableLight();
        r.enableDepthTest();
        r.enableFaceCulling();

        r.drawTerrain(terrain);

        r.disableLight();
        r.disableDepthTest();
        r.disableFaceCulling();

        r.drawAxes();
    }

    @Override
    public boolean isFinished() {
        return escapePressed.isPressed();
    }

}
